package xyz.mumuwei.youthcourseserver.service.impl;

import com.anji.captcha.service.CaptchaCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.mumuwei.youthcourseserver.utils.RedisUtil;

import java.util.concurrent.TimeUnit;

/**
 * 图形验证码数据库操作
 * @author mumuwei
 * @date 2022/2/20
 */
@Service
public class CaptchaCacheServiceRedisImpl implements CaptchaCacheService {

    private RedisUtil redisUtil;

    @Autowired
    public void setRedisUtil(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }

    @Override
    public void set(String s, String s1, long l) {
        redisUtil.set(s, s1, l, TimeUnit.SECONDS);
    }

    @Override
    public boolean exists(String s) {
        return redisUtil.hasKey(s);
    }

    @Override
    public void delete(String s) {
        redisUtil.delete(s);
    }

    @Override
    public String get(String s) {
        return (String) redisUtil.get(s);
    }

    @Override
    public String type() {
        return "redis";
    }

    @Override
    public Long increment(String key, long val) {
        return redisUtil.increment(key, val);
    }
}
